#include<iostream>
#include<unistd.h>
#include<stdlib.h>
#include<sys/wait.h>

int main()
{
    pid_t id = fork();
    if(id == 0){
        int cnt = 10;
        while(cnt){
            std:: cout << "我是子进程:" <<getpid() << ' ' << "父进程:" << getppid() << " cnt:" << cnt-- << std::endl;
            sleep(1);
            _exit(11);
            int* p = nullptr;
            *p = 1000;
        }
    }

    int status = 0;
    pid_t myid = waitpid(id,&status,0);
    if(id > 0){
        std::cout << "wait success:" << myid << " sig number" << (status&0x7F) << " child exit code" << ((status>>8)&0xFF) << std::endl;
    }
    sleep(5);
}
